<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\service\ocean;

use app\enum\OeUrlEnum;
use proxy\Client;

final class MaterialService extends OceanService
{
    /**
     * 获取图片列表.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getImageList(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('material');
            $serviceUrl = OeUrlEnum::getServiceUrl('material', 'image_list');

            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (! self::isResponseSuccess(intval($res['code']))) {
                return self::setError($res['message']);
            }
            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 批量暂停素材.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function setVideoPause(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('material');
            $serviceUrl = OeUrlEnum::getServiceUrl('material', 'video_pause');

            $res = $client->postJson($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (! self::isResponseSuccess(intval($res['code']))) {
                return self::setError($res['message'] . '==' . $res['request_id'] . '==' . $res['code']);
            }
            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

    /**
     * 按账户批量暂停素材.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function setPromotionVideoPause(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('material');
            $serviceUrl = OeUrlEnum::getServiceUrl('material', 'promotion_video_pause');

            $res = $client->postJson($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (! self::isResponseSuccess(intval($res['code']))) {
                return self::setError($res['message']);
            }
            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }


    /**
     * 获取图文素材.
     * @param array $headers 头信息
     * @param array $params 参数
     * @return bool|mixed|string
     */
    public static function getCarouselList(array $headers = [], array $params = [])
    {
        try {
            $client = new Client();
            $serviceName = OeUrlEnum::getServiceName('material');
            $serviceUrl = OeUrlEnum::getServiceUrl('material', 'carousel_list');

            $res = $client->get($serviceName, $serviceUrl, $params)->setHeader($headers)->exec(Client::RETURN_TYPE);
            if (! self::isResponseSuccess(intval($res['code']))) {
                return self::setError($res['message']);
            }
            return $res;
        } catch (\Exception $e) {
            return self::setError($e->getMessage());
        }
    }

}
